//目录树
var selectedNode = null;

function clickOnNode(node) {
	if(node.open == "false" || node.open == undefined) {
		expand(node, true);
	}else{
		collapse(node);
	}
}

function openNode(node) {
	var obj;
	var url;
	var target;
	var form;
	
	if (node == null || node == undefined){
		window.location = "../loginout.jsp";
		return;
	}

	obj = document.getElementById(node.id.substr(3));
	//clickOnNode(obj);

	if (selectedNode != null){
		if (selectedNode.opennode.markinred == "1"){
			selectedNode.opennode.className = "nonsel_markinred";
		}else{
			selectedNode.opennode.className = "nonsel";
		}
	}

	selectedNode = obj;
	selectedNode.opennode = node;
	if (node.markinred == "1"){
		node.className = "sel_markinred";
	}else{
		node.className = "sel";
	}
	//window.event.cancelBubble = "true";

    //alert(node.innerText);
	url = selectedNode.attributes["url"].nodeValue;
	if (url == undefined || url.length < 1){
		url = "body.htm"
	}
	target = selectedNode.attributes["target"].nodeValue;
	if (target == undefined || target.length < 1){
		target = "main"
	}
	
	form = document.forms["ready"];
	form.attributes["action"].nodeValue=url;
	form.attributes["target"].nodeValue=target;
	form.submit();
	//window.open(url,target);

	//window.returnValue = node.innerText;
	//window.close();
}

function expand(node) {
	var stateImage;
	var oImage;
	
	stateImage = document.getElementById("stateImage" + node.id);
	//oImage = node.childNodes[0].all["image"];
	oImage = this.getChildNode(node,"image");
	oImage.src = node.attributes["imageOpen"].nodeValue;

	if(stateImage){
		stateImage.src = stateImage.attributes["_open"].nodeValue;
	}

	for(i=0; i < node.childNodes.length; i++) {
		if(node.childNodes[i].tagName == "DIV") {
			node.childNodes[i].style.display = "block";
		}
	}
  
	node.open = "true";
}

function collapse(node) {
	var stateImage;
	var oImage;
	var i;

	stateImage = document.getElementById("stateImage" + node.id);
	//oImage = node.getElementsByTagName("image").childNodes[0];
	oImage = this.getChildNode(node,"image");
	oImage.src = node.attributes["image"].nodeValue;

	if(stateImage){
		stateImage.src = stateImage.attributes["_closed"].nodeValue;
	}

	for(i=0; i < node.childNodes.length; i++) {
		if(node.childNodes[i].tagName == "DIV") {
			node.childNodes[i].style.display = "none";
			collapse(node.childNodes[i]);
		}
	}
    
	node.open = "false";
}

function expandAll(node) {
	var oImage;
	var i;

	expand(node, false);

	for(i=0; i < node.childNodes.length; i++) {
		if(node.childNodes[i].tagName == "DIV") {
			expandAll(node.childNodes[i]);
		}
	}
}

// 展开选中接点
function expandSelectedNode(node) {
	var oImage;
	var obj;
	var i;
	
	obj = document.getElementById(node.id.substr(3));

	// 展开当前接点
	expand(obj, false);
	
	// 展开父级接点
	expandParentNode(obj);
}

// 展开选中父亲接点
function expandParentNode(node){
	var pNode;
	
	if (node == null || 
		node == undefined || 
		node == "null" || 
		node == ""){
		return;
	}
	// 父级接点
	pNode = getParentNode(node);
	if (node != null && 
		node != undefined && 
		node != "null" && 
		node != ""){
		expandParentNode(pNode);
	}
	// 展开当前接点
	expand(node, false);
}

// 获得父级接点
function getParentNode(node){
	var result = null;
	var pNode;

	if (node == null || 
		node == undefined || 
		node == "null" || 
		node == ""){
		return result;
	}
	// 父级接点
	pNode = node.parentNode;
	if (pNode == null || 
		pNode == undefined || 
		pNode == "null" || 
		pNode == ""){
		return result;
	}
	if(pNode.tagName == "DIV") {
		result = pNode;
	}else{
		result = getParentNode(pNode);
	}

	return result;
}

//获得指定ID的子接点对象
function getChildNode(parent,childId){
	var result = null;
	var childNodes = null;
	var len;
	var i;
	var name = null;
	var id = null;

	if (parent == null || 
		parent == undefined || 
		parent == "null" || 
		parent == ""){
		return result;
	}
	if (childId == null || 
		childId == undefined || 
		childId == "null" || 
		childId == ""){
		return result;
	}
	childNodes = parent.childNodes;
	if (childNodes == null || 
		childNodes == undefined || 
		childNodes == "null" || 
		childNodes == ""){
		return result;
	}
	len = childNodes.length;
	if (len == null || 
		len == undefined || 
		len == "null" || 
		len == ""){
		return result;
	}
	for(i=0; i < len; i++) {
		id = childNodes[i].id;
		name = childNodes[i].name;
		if(id == childId || name == childId) {
			result = childNodes[i];
			break;
		}
		result = this.getChildNode(childNodes[i],childId);
		if (result != null){
			break;
		}
	}
	return result;
}
